package org.pp.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.pp.admin.dto.PpGoodsPage;
import org.pp.admin.dto.PpUserPage;
import org.pp.admin.dto.PpUserStatusSwitch;
import org.pp.admin.dto.SysUserStatusSwitch;
import org.pp.annotations.Permission;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.entity.PpUser;
import org.pp.service.IPpUserService;
import org.pp.store.OssStore;
import org.pp.vo.AdminGoodsVo;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class PpUserController extends BaseCrudController<PpUser,PpUser,PpUser,PpUser> {

    @Autowired
    OssStore ossStore;

    @Autowired
    IPpUserService userService;

    @GetMapping("/list")
    @Permission("get:/user/list")
    @Operation(summary = "分页查询")
    public Result<PageBean<PpUser>> page(@ParameterObject PpUserPage page) {
        Result<PageBean<PpUser>> pg = super.page(page);
        pg.getData().getList().forEach(e-> e.setAvatar(ossStore.getUrl(e.getAvatar())));
        return pg;
    }

    @PostMapping("/status/switch")
    @Operation(summary = "修改注册用户状态 禁用与激活")
    @Permission("post:/user/status/switch")
    public Result<Void> statusSwitch(@RequestBody @Validated PpUserStatusSwitch dto){
        userService.statusSwitch(dto);
        return Result.ok();
    }


}
